package com.htht.job.admin.controller;

/**
 * Created by zzj on 2018/1/10.
 */

import com.alibaba.dubbo.common.json.JSON;
import com.alibaba.dubbo.common.json.ParseException;
import com.htht.job.core.api.parameter.JobParameterService;
import com.htht.job.executor.model.parameter.JobParameterModel;
import com.htht.job.executor.model.paramtemplate.DownParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/template")
public class ParamTemplateController {
    @Autowired
    private JobParameterService jobParameterService;

    @RequestMapping("/down")
    public String down(Model model,String jobId) {
        try {
            JobParameterModel jobParameterModel=jobParameterService.findJobParameterById(jobId);
            DownParam downParam;
            if(jobParameterModel==null){
                 downParam=new DownParam();
            }else{
                 downParam= JSON.parse(jobParameterModel.getModelParameters(),DownParam.class);

            }
            model.addAttribute("downParam", downParam);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "/paramtemplate/downparam";
    }

}
